﻿using DevExpress.XtraEditors;
using DoAnQuamLy.DataAccess;
using DoAnQuamLy.Object;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DoAnQuamLy.Controller
{
    class PhieuChiController
    {
        PhieuChiData data = new PhieuChiData();
        public void SapXepDuLieuLenPhieuchi(TextEdit txt_SoPhieuChi, DateEdit dtp_Ngay, ComboBoxEdit cmb_LoaiPhieuChi, TextEdit txt_LiDoChi, TextEdit txt_ChungTuGoc, TextEdit txt_NguoiNhan, TextEdit txt_DiaChi, NumericUpDown nud_SoTien, TextBox txt_GhiChu)
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = data.Phieuchi();
            txt_SoPhieuChi.DataBindings.Add("Text", bs, "Sophieuchi");
            dtp_Ngay.DataBindings.Add("Text", bs, "Ngay");
            cmb_LoaiPhieuChi.DataBindings.Add("Text", bs, "Loaiphieuchi");
            txt_LiDoChi.DataBindings.Add("Text", bs, "Lidochi");
            txt_ChungTuGoc.DataBindings.Add("Text", bs, "Chungtugoc");
            txt_NguoiNhan.DataBindings.Add("Text", bs, "Nguoinhan");
            txt_DiaChi.DataBindings.Add("Text", bs, "Diachi");
            nud_SoTien.DataBindings.Add("Text", bs, "Sotien");
            txt_GhiChu.DataBindings.Add("Text", bs, "Ghichu");
        }
        public List<PhieuChiObject> DangKy()
        {
            List<PhieuChiObject> DK = new List<PhieuChiObject>();
            DataTable dt = data.Phieuchi();
            int k = dt.Rows.Count;
            for (int i = 0; i < k; i++)
            {
                PhieuChiObject ok = new PhieuChiObject();
                ok.SoPhieuChi = dt.Rows[i]["Sophieuchi"].ToString();
                ok.Ngay = Convert.ToDateTime(dt.Rows[i]["Ngay"].ToString());
                ok.LoaiPhieuChi = dt.Rows[i]["Loaiphieuchi"].ToString();
                ok.LiDoChi = dt.Rows[i]["Lidochi"].ToString();
                ok.ChungTuGoc = dt.Rows[i]["Chungtugoc"].ToString();
                ok.NguoiNhan = dt.Rows[i]["Nguoinhan"].ToString();
                ok.DiaChi = dt.Rows[i]["Diachi"].ToString();
                ok.SoTien = Convert.ToInt32(dt.Rows[i]["Sotien"].ToString());
                ok.GhiChu = dt.Rows[i]["Ghichu"].ToString();
                DK.Add(ok);
            }
            return DK;
        }
        public void Update()
        {
            data.Update();
        }
    }
}
